package net.mcreator.servercmd.procedure;

import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.common.MinecraftForge;

import net.minecraft.world.World;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.BlockPos;
import net.minecraft.server.MinecraftServer;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.Score;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.Entity;
import net.minecraft.command.ICommandSender;

import net.mcreator.servercmd.ElementsServerCmdMod;

import java.util.Map;

@ElementsServerCmdMod.ModElement.Tag
public class ProcedureRegisterTick extends ElementsServerCmdMod.ModElement {
	public ProcedureRegisterTick(ElementsServerCmdMod instance) {
		super(instance, 15);
	}

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			System.err.println("Failed to load dependency entity for procedure RegisterTick!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		if ((((new TextComponentTranslation("login").getUnformattedComponentText())).equals("true"))) {
			if (((new Object() {
				public int getScore(String score) {
					if (entity instanceof EntityPlayer) {
						Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
						ScoreObjective _so = _sc.getObjective(score);
						if (_so != null) {
							Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
							return _scr.getScorePoints();
						}
					}
					return 0;
				}
			}.getScore("SetGM")) == 1)) {
				if (((new Object() {
					public int getScore(String score) {
						if (entity instanceof EntityPlayer) {
							Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
							ScoreObjective _so = _sc.getObjective(score);
							if (_so != null) {
								Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
								return _scr.getScorePoints();
							}
						}
						return 0;
					}
				}.getScore("register")) != 1)) {
					entity.getEntityData().setDouble("regMsgTime", ((entity.getEntityData().getDouble("regMsgTime")) + 1));
					if (((entity.getEntityData().getDouble("regMsgTime")) >= 40)) {
						if (entity instanceof EntityPlayer && !entity.world.isRemote) {
							((EntityPlayer) entity).sendStatusMessage(new TextComponentString(
									"\u00A7c\u60A8\u5C1A\u672A\u6CE8\u518C\u8D26\u6237\uFF0C\u8BF7\u8F93\u5165 /register \u5BC6\u7801 \u6765\u8FDB\u884C\u6CE8\u518C"),
									(false));
						}
						entity.getEntityData().setDouble("regMsgTime", 0);
						{
							Entity _ent = entity;
							if (!_ent.world.isRemote && _ent.world.getMinecraftServer() != null) {
								_ent.world.getMinecraftServer().getCommandManager().executeCommand(new ICommandSender() {
									@Override
									public String getName() {
										return "";
									}

									@Override
									public boolean canUseCommand(int permission, String command) {
										return true;
									}

									@Override
									public World getEntityWorld() {
										return _ent.world;
									}

									@Override
									public MinecraftServer getServer() {
										return _ent.world.getMinecraftServer();
									}

									@Override
									public boolean sendCommandFeedback() {
										return false;
									}

									@Override
									public BlockPos getPosition() {
										return _ent.getPosition();
									}

									@Override
									public Vec3d getPositionVector() {
										return new Vec3d(_ent.posX, _ent.posY, _ent.posZ);
									}

									@Override
									public Entity getCommandSenderEntity() {
										return _ent;
									}
								}, "playsound minecraft:entity.experience_orb.pickup player @s");
							}
						}
					}
				}
				if ((((new Object() {
					public int getScore(String score) {
						if (entity instanceof EntityPlayer) {
							Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
							ScoreObjective _so = _sc.getObjective(score);
							if (_so != null) {
								Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
								return _scr.getScorePoints();
							}
						}
						return 0;
					}
				}.getScore("register")) == 1) && ((new Object() {
					public int getScore(String score) {
						if (entity instanceof EntityPlayer) {
							Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
							ScoreObjective _so = _sc.getObjective(score);
							if (_so != null) {
								Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
								return _scr.getScorePoints();
							}
						}
						return 0;
					}
				}.getScore("login")) != 1))) {
					entity.getEntityData().setDouble("regMsgTime", ((entity.getEntityData().getDouble("regMsgTime")) + 1));
					if (((entity.getEntityData().getDouble("regMsgTime")) >= 40)) {
						if (entity instanceof EntityPlayer && !entity.world.isRemote) {
							((EntityPlayer) entity).sendStatusMessage(new TextComponentString(
									"\u00A7c\u60A8\u5C1A\u672A\u767B\u5F55\uFF0C\u8BF7\u8F93\u5165 /login \u5BC6\u7801 \u8FDB\u884C\u767B\u5F55"),
									(false));
						}
						entity.getEntityData().setDouble("regMsgTime", 0);
						{
							Entity _ent = entity;
							if (!_ent.world.isRemote && _ent.world.getMinecraftServer() != null) {
								_ent.world.getMinecraftServer().getCommandManager().executeCommand(new ICommandSender() {
									@Override
									public String getName() {
										return "";
									}

									@Override
									public boolean canUseCommand(int permission, String command) {
										return true;
									}

									@Override
									public World getEntityWorld() {
										return _ent.world;
									}

									@Override
									public MinecraftServer getServer() {
										return _ent.world.getMinecraftServer();
									}

									@Override
									public boolean sendCommandFeedback() {
										return false;
									}

									@Override
									public BlockPos getPosition() {
										return _ent.getPosition();
									}

									@Override
									public Vec3d getPositionVector() {
										return new Vec3d(_ent.posX, _ent.posY, _ent.posZ);
									}

									@Override
									public Entity getCommandSenderEntity() {
										return _ent;
									}
								}, "playsound minecraft:entity.experience_orb.pickup player @s");
							}
						}
					}
				}
				(entity).extinguish();
				if (entity instanceof EntityLivingBase)
					((EntityLivingBase) entity).setHealth((float) (new Object() {
						public int getScore(String score) {
							if (entity instanceof EntityPlayer) {
								Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
								ScoreObjective _so = _sc.getObjective(score);
								if (_so != null) {
									Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
									return _scr.getScorePoints();
								}
							}
							return 0;
						}
					}.getScore("HelathTempS")));
				{
					Entity _ent = entity;
					if (!_ent.world.isRemote && _ent.world.getMinecraftServer() != null) {
						_ent.world.getMinecraftServer().getCommandManager().executeCommand(new ICommandSender() {
							@Override
							public String getName() {
								return "";
							}

							@Override
							public boolean canUseCommand(int permission, String command) {
								return true;
							}

							@Override
							public World getEntityWorld() {
								return _ent.world;
							}

							@Override
							public MinecraftServer getServer() {
								return _ent.world.getMinecraftServer();
							}

							@Override
							public boolean sendCommandFeedback() {
								return false;
							}

							@Override
							public BlockPos getPosition() {
								return _ent.getPosition();
							}

							@Override
							public Vec3d getPositionVector() {
								return new Vec3d(_ent.posX, _ent.posY, _ent.posZ);
							}

							@Override
							public Entity getCommandSenderEntity() {
								return _ent;
							}
						}, (("tp @s ") + "" + ((new Object() {
							public int getScore(String score) {
								if (entity instanceof EntityPlayer) {
									Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
									ScoreObjective _so = _sc.getObjective(score);
									if (_so != null) {
										Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
										return _scr.getScorePoints();
									}
								}
								return 0;
							}
						}.getScore("LoginX"))) + "" + (" ") + "" + ((new Object() {
							public int getScore(String score) {
								if (entity instanceof EntityPlayer) {
									Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
									ScoreObjective _so = _sc.getObjective(score);
									if (_so != null) {
										Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
										return _scr.getScorePoints();
									}
								}
								return 0;
							}
						}.getScore("LoginY"))) + "" + (" ") + "" + ((new Object() {
							public int getScore(String score) {
								if (entity instanceof EntityPlayer) {
									Scoreboard _sc = ((EntityPlayer) entity).getWorldScoreboard();
									ScoreObjective _so = _sc.getObjective(score);
									if (_so != null) {
										Score _scr = _sc.getOrCreateScore(((EntityPlayer) entity).getGameProfile().getName(), _so);
										return _scr.getScorePoints();
									}
								}
								return 0;
							}
						}.getScore("LoginZ")))));
					}
				}
				{
					Entity _ent = entity;
					if (!_ent.world.isRemote && _ent.world.getMinecraftServer() != null) {
						_ent.world.getMinecraftServer().getCommandManager().executeCommand(new ICommandSender() {
							@Override
							public String getName() {
								return "";
							}

							@Override
							public boolean canUseCommand(int permission, String command) {
								return true;
							}

							@Override
							public World getEntityWorld() {
								return _ent.world;
							}

							@Override
							public MinecraftServer getServer() {
								return _ent.world.getMinecraftServer();
							}

							@Override
							public boolean sendCommandFeedback() {
								return false;
							}

							@Override
							public BlockPos getPosition() {
								return _ent.getPosition();
							}

							@Override
							public Vec3d getPositionVector() {
								return new Vec3d(_ent.posX, _ent.posY, _ent.posZ);
							}

							@Override
							public Entity getCommandSenderEntity() {
								return _ent;
							}
						}, "gamemode 2 @s");
					}
				}
			}
		}
	}

	@SubscribeEvent
	public void onPlayerTick(TickEvent.PlayerTickEvent event) {
		if (event.phase == TickEvent.Phase.END) {
			Entity entity = event.player;
			World world = entity.world;
			int i = (int) entity.posX;
			int j = (int) entity.posY;
			int k = (int) entity.posZ;
			java.util.HashMap<String, Object> dependencies = new java.util.HashMap<>();
			dependencies.put("x", i);
			dependencies.put("y", j);
			dependencies.put("z", k);
			dependencies.put("world", world);
			dependencies.put("entity", entity);
			dependencies.put("event", event);
			this.executeProcedure(dependencies);
		}
	}

	@Override
	public void preInit(FMLPreInitializationEvent event) {
		MinecraftForge.EVENT_BUS.register(this);
	}
}
